#include "stdafx.h"
#include "BaseShape.h"

IMPLEMENT_SERIAL (BaseShape, CObject, 1)
BaseShape::BaseShape(void)
{

}

BaseShape::BaseShape(CPoint pBegin, CPoint pEnd, COLORREF Back)
{
	this->m_pBegin	= pBegin;
	this->m_pEnd	= pEnd;
	this->m_cPenColor = Back;
}

BOOL BaseShape::Draw(CDC *cDC)
{
	return FALSE;
}

BaseShape::~BaseShape(void)
{
	delete []m_pCoordinates;
}

void LineEquation(INT &A, INT &B, INT &C, CPoint X, CPoint Y)
{
	A = Y.y - X.y;
	B = X.x - Y.x;
	C = X.y * Y.x - X.x * Y.y;
}

CPoint PointCenter(CPoint X1, CPoint Y1, CPoint X2, CPoint Y2)
{
	INT A1, B1, C1, A2, B2, C2;
	CPoint KQ;
	LineEquation(A1, B1, C1, X1, Y1);
	LineEquation(A2, B2, C2, X2, Y2);
	
	KQ.x = (float)(-B1 * C2 + B2 * C1) / (- B1 * A2 + B2 * A1);
	KQ.y = (float)(-A1 * C2 + A2 * C1) / (- B1 * A2 + B2 * A1);

	return KQ;
}

BaseShape::BaseShape (CPoint m_pBegin, CPoint m_pEnd, COLORREF m_clrBack, COLORREF m_cPenColor, BASESHAPE__T m_nShapeType, CString m_szText, COLORREF m_color)
{
	this->m_pBegin = m_pBegin;
	this->m_pEnd = m_pEnd;
	this->m_clrBack = m_clrBack;
	this->m_cPenColor = m_cPenColor;
	this->m_nShapeType = m_nShapeType;
	this->m_szText = m_szText;
	this->m_color = m_color;
}

void BaseShape::Serialize (CArchive &ar)
{
	if (ar.IsStoring() )
	{
		ar << m_pBegin << m_pEnd << m_clrBack << m_cPenColor << m_nShapeType << m_szText << m_color << m_nRotate;
	}
	else
	{
		int nShapeType;
		ar >> m_pBegin >> m_pEnd >> m_clrBack >> m_cPenColor >> nShapeType >> m_szText >> m_color >> m_nRotate;
		m_nShapeType = (BASESHAPE__T)nShapeType;
	}
}